package thread.matrix.group;

/**
 * 按cpu核数创建线程，执行任务
 */
public class GroupMultiplierTask implements Runnable{
    //加final保证可见性，避免线程冲突
    private final double[][] matrix1;
    private final double[][] matrix2;
    private final double[][] result;
    private final int start;//matrix1的当前行数
    private final int end;//matrix2的当前列数
    public GroupMultiplierTask(double[][] matrix1, double[][] matrix2, double[][] result, int start, int end) {
        this.matrix1 = matrix1;
        this.matrix2 = matrix2;
        this.result = result;
        this.start = start;
        this.end = end;
    }

    @Override
    public void run() {
        for(int i=start;i<end;i++){//start行开始，end结束
            for(int j=0;j<matrix2[0].length;j++){//matrix2的列数
                //初始化结果矩阵
                result[i][j] = 0;
                for(int k=0;k<matrix1.length;k++){//
                    //矩阵的乘法,result[i][j],第i行，第j列
                    //计算结果矩阵的值
                    result[i][j] += matrix1[i][k]*matrix2[k][j];
                    System.out.println("result["+i+"]"+"["+j+"]"+result[i][j]);
                }
            }
        }
    }
}
